package pATT.DataSetsGenerator.dataSetsGenerator.generator.visual;


import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import pATT.DataSetsGenerator.dataSetsGenerator.associationManager.implement.AssociationManager;
import pATT.DataSetsGenerator.dataSetsGenerator.associationManager.implement.AssociationRule;
import pATT.DataSetsGenerator.dataSetsGenerator.attribute.implement.Attribute;
import pATT.DataSetsGenerator.dataSetsGenerator.core.implement.Relation;
import pATT.DataSetsGenerator.dataSetsGenerator.core.implement.RelationManager;
import pATT.help.visual.HelpFrame;
import pATT.logger.Message;


@SuppressWarnings("serial")
public class AssociationFrame extends JFrame {
	
	private JPanel jContentPane = null;
	private JLabel jLabel = null;
	private JPanel jPanel = null;
	private JLabel jLabel1 = null;
	private JButton jButton = null;
	private JButton jButton1 = null;
	private JLabel jLabel2 = null;
	private JComboBox jComboBox = null;
	private JButton jButton2 = null;
	private JButton jButton3 = null;
	private JLabel jLabel3 = null;
	private JLabel jLabel4 = null;
	private JLabel jLabel5 = null;
	private JLabel jLabel6 = null;
	private JTextField jTextField = null;
	private JTextField jTextField2 = null;
	private JTextField jTextField3 = null;
	private JLabel jLabel8 = null;
	private JLabel jLabel9 = null;
	private JScrollPane jScrollPane = null;
	private JLabel jLabel10 = null;
	private JLabel jStep2Label11 = null;
	private JPanel jRulesPanel1 = null;
	private JLabel jRulesLabel7 = null;
	private JComboBox jComboBox1 = null;
	private JLabel jStep3Label7 = null;
	private JLabel jerrorLabel7 = null;
	private Relation relation = null;
	private Vector<Attribute> relationCopy= new Vector<Attribute>();
	private JTextArea jTextArea = null;
	int cantAddClick = 0;
	private JPanel jPanel1 = null;
	private AssociationManager assocManager = null;
	private JButton jHelpButton = null;
	
	/**
	 * This is the default constructor
	 */
	public AssociationFrame() {
		super();
		relation = RelationManager.instance.getCurrentRelation();
		assocManager = new AssociationManager(relation);
		initialize();
				
	}
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {

		
		this.setBackground(java.awt.SystemColor.control);
		this.setSize(568, 579);
		this.setResizable(false);
		this.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
		this.setContentPane(getJContentPane());
		this.setTitle("Relation Generator Rule - Association Generation Random");
		Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension freim = this.getSize();
		if (pantalla.width < freim.width){
			freim.width = pantalla.width;
		}
		if (pantalla.height < freim.height) {
			freim.height = pantalla.height;
		}
		this.setLocation((pantalla.width-freim.width)/2,(pantalla.height-freim.height)/2);

		
		jLabel10.setText(relation.getName());
		
	}
	
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel10 = new JLabel();
			jLabel10.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.BOLD, 14));
			jLabel10.setPreferredSize(new java.awt.Dimension(150,16));
			jLabel10.setLocation(new java.awt.Point(103,16));
			jLabel10.setSize(new java.awt.Dimension(190,16));
			jLabel10.setBackground(java.awt.SystemColor.control);
			jLabel10.setText("<Relations1>");
			jLabel = new JLabel();
			jLabel.setBounds(new java.awt.Rectangle(26,16,74,16));
			jLabel.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.BOLD, 14));
			jLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
			jLabel.setBackground(java.awt.SystemColor.control);
			jLabel.setText("Relation :");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jContentPane.setBackground(java.awt.SystemColor.control);
			jContentPane.add(jLabel, null);
			jContentPane.add(getJPanel(), null);
			jContentPane.add(getJButton2(), null);
			jContentPane.add(getJButton3(), null);
			jContentPane.add(jLabel10, null);
			jContentPane.add(getJHelpButton(), null);
		}
		return jContentPane;
	}
	
	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jerrorLabel7 = new JLabel();
			jerrorLabel7.setForeground(java.awt.Color.red);
			//jerrorLabel7.setText("\"Please, complete support and confidence\"");
			jerrorLabel7.setSize(new java.awt.Dimension(227,23));
			jerrorLabel7.setLocation(new java.awt.Point(15,85));
			jerrorLabel7.setVisible(false);
			jStep3Label7 = new JLabel();
			jStep3Label7.setText("Step 3: Set support and confidence");
			jStep3Label7.setSize(new java.awt.Dimension(180,23));
			jStep3Label7.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jStep3Label7.setForeground(java.awt.Color.blue);
			jStep3Label7.setLocation(new java.awt.Point(14,5));
			jStep3Label7.setVisible(false);
			jStep2Label11 = new JLabel();
			jStep2Label11.setText("Step 2: Set consecuent");
			jStep2Label11.setLocation(new java.awt.Point(14,5));
			jStep2Label11.setForeground(java.awt.Color.blue);
			jStep2Label11.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jStep2Label11.setSize(new java.awt.Dimension(120,23));
			jStep2Label11.setVisible(false);
			jLabel9 = new JLabel();
			jLabel9.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jLabel9.setSize(new java.awt.Dimension(60,22));
			jLabel9.setLocation(new java.awt.Point(140,61));
			jLabel9.setText("[1..100] %");
			jLabel9.setVisible(false);
			jLabel8 = new JLabel();
			jLabel8.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jLabel8.setText("[1..100] %");
			jLabel8.setSize(new java.awt.Dimension(60,22));
			jLabel8.setLocation(new java.awt.Point(140,36));
			jLabel8.setVisible(false);
			jLabel6 = new JLabel();
			jLabel6.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jLabel6.setLocation(new java.awt.Point(15,62));
			jLabel6.setSize(new java.awt.Dimension(83,18));
			jLabel6.setText("Confidence");
			jLabel6.setVisible(false);
			jLabel5 = new JLabel();
			jLabel5.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jLabel5.setLocation(new java.awt.Point(15,37));
			jLabel5.setSize(new java.awt.Dimension(57,18));
			jLabel5.setText("Support");
			jLabel5.setVisible(false);
			jLabel4 = new JLabel();
			jLabel4.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jLabel4.setLocation(new java.awt.Point(15,86));
			jLabel4.setSize(new java.awt.Dimension(57,18));
			jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			jLabel4.setText("Value");
			jLabel3 = new JLabel();
			jLabel3.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jLabel3.setLocation(new java.awt.Point(15,62));
			jLabel3.setSize(new java.awt.Dimension(57,18));
			jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			jLabel3.setText("Type");
			jLabel2 = new JLabel();
			jLabel2.setBounds(new java.awt.Rectangle(15,37,57,18));
			jLabel2.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			jLabel2.setText("Attribute");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new java.awt.Rectangle(14,5,121,23));
			jLabel1.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jLabel1.setForeground(java.awt.Color.blue);
			jLabel1.setText("Step 1: Set antecedent");
			jLabel1.setVisible(true);
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
			jPanel.setBackground(java.awt.SystemColor.activeCaptionBorder);
			jPanel.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jPanel.setForeground(java.awt.Color.blue);
			jPanel.setLocation(new java.awt.Point(15,45));
			jPanel.setSize(new java.awt.Dimension(529,450));
			jPanel.setVisible(true);
			jPanel.add(jLabel1, null);
			jPanel.add(jLabel2, null);
			jPanel.add(getJComboBox(), null);
			jPanel.add(jLabel3, null);
			jPanel.add(jLabel4, null);
			jPanel.add(jLabel5, null);
			jPanel.add(jLabel6, null);
			jPanel.add(getJTextField(), null);
			jPanel.add(getJTextField2(), null);
			jPanel.add(getJTextField3(), null);
			jPanel.add(jLabel8, null);
			jPanel.add(jLabel9, null);
			jPanel.add(getJScrollPane(), null);
			jPanel.add(jStep2Label11, null);
			jPanel.add(getJRulesPanel1(), null);
			jPanel.add(getJComboBox1(), null);
			jPanel.add(jStep3Label7, null);
			jPanel.add(jerrorLabel7, null);
			jPanel.add(getJPanel1(), null);
		}
		return jPanel;
	}
	
	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jButton.setText("Add");
			jButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jButton.setLocation(new java.awt.Point(67,11));
			jButton.setSize(new java.awt.Dimension(80,25));
			jButton.setBackground(java.awt.SystemColor.activeCaptionBorder);
			jButton.setEnabled(true);
			jButton.addActionListener(new java.awt.event.ActionListener() {
				int index;
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					
					if(jComboBox.getSelectedIndex()!= -1){
						jButton1.setEnabled(true);
						index=jComboBox.getSelectedIndex();
						//jComboBox.removeItemAt(jComboBox.getSelectedIndex());
						//jComboBox tengo que seleccionar simpre -1 despues de borrar
						
						//relationCopy.removeElementAt(index);
						
						
						if((jLabel1.isVisible())&&(!(jStep2Label11.isVisible()))){
							AssociationRule ass;
							if(assocManager.getAssociations().size()== 0){
								ass = new AssociationRule();
							}
							else{
								if(assocManager.getAssociations().lastElement().getConfidence()!=0){
									ass = new AssociationRule();
								}						
								else{
									ass= assocManager.getAssociations().lastElement();
									int i=assocManager.getAssociations().size();
									assocManager.getAssociations().removeElementAt(i-1);
								}
							}
							if((jComboBox != null )&&(jComboBox1 != null)){
								
								ass.setAntecedent(jComboBox.getSelectedItem().toString());
								ass.setAntecedent(jComboBox1.getSelectedItem().toString());
								assocManager.setAssociation(ass);
								//System.out.println("Step1: "+AssociationManager.instanceAssociationManager.getAssociations().lastElement().getAntecedents().lastElement());
							}
						}
						if ((!jLabel1.isVisible())&&(jStep2Label11.isVisible())){
							if((jComboBox != null )&& (jComboBox1 != null)){ 
								AssociationRule assoc = assocManager.getAssociations().lastElement();
								int j=assocManager.getAssociations().size();
								assocManager.getAssociations().removeElementAt(j-1);
								//assocManager.getAssociations().remove(assoc);//ver si esto borra el elemento anterior
								assoc.setConsecuent(jComboBox.getSelectedItem().toString());
								assoc.setConsecuent(jComboBox1.getSelectedItem().toString());
								assocManager.setAssociation(assoc);
								//System.out.println("Step2: "+AssociationManager.instanceAssociationManager.getAssociations().lastElement().getConsecuents().lastElement());
								
							}
						}
						
						
						
						
					}
					
					jComboBox.removeItemAt(jComboBox.getSelectedIndex());
					jComboBox1.removeAllItems();
					if(jComboBox.getItemCount()==0)
						jButton.setEnabled(false);
					jComboBox.setSelectedIndex(-1);
					jTextField.setText("");
					jTextField.setEditable(false);
					relationCopy.removeElementAt(index);
				}
				
			});
		}
		
		return jButton;
	}
	
	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jButton1.setText("Finish");
			jButton1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jButton1.setLocation(new java.awt.Point(67,47));
			jButton1.setSize(new java.awt.Dimension(80,25));
			jButton1.setBackground(java.awt.SystemColor.activeCaptionBorder);
			jButton1.setEnabled(false);
			jButton1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					
					jerrorLabel7.setVisible(false);
					jLabel9.setForeground(java.awt.Color.black);
					jLabel9.setFont(new java.awt.Font("Microsoft Sans Serif",java.awt.Font.PLAIN, 11));
					jLabel8.setForeground(java.awt.Color.black);
					jLabel8.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
					if(jLabel1.isVisible()&&(!(jStep2Label11.isVisible()))){
						jLabel1.setVisible(false);
						jStep2Label11.setVisible(true);
						jButton.setEnabled(true);
						//relationCopy.removeAllElements();
						//relationCopy.addAll(relation.getAtributes());
						jComboBox.removeAllItems();
						for (int i = 0; i < relationCopy.size(); i++) {
							jComboBox.addItem(relationCopy.elementAt(i).getName());
						}
						
						jButton1.setEnabled(false);
						jerrorLabel7.setVisible(false);
						jTextField.setText("");
						jComboBox.setSelectedIndex(-1);
						jComboBox1.setSelectedIndex(-1);
						
					}else{
						if(!(jLabel1.isVisible())&&(jStep2Label11.isVisible())){
							relationCopy.removeAllElements();
							relationCopy.addAll(relation.getAtributes());
							jComboBox.removeAllItems();
							for (int i = 0; i < relationCopy.size(); i++) {
								jComboBox.addItem(relationCopy.elementAt(i).getName());
							}
							//jComboBox.repaint();
							jButton1.setEnabled(false);
							jerrorLabel7.setVisible(false);
							jStep2Label11.setVisible(false);
							jLabel2.setVisible(false);
							jLabel3.setVisible(false);
							jLabel4.setVisible(false);
							jLabel5.setVisible(true);
							jLabel6.setVisible(true);
							jTextField2.setVisible(true);
							jTextField3.setVisible(true);
							jLabel8.setVisible(true);							
							jLabel9.setVisible(true);
							jComboBox.setVisible(false);
							jTextField.setVisible(false);
							jComboBox1.setVisible(false);
							jButton.setEnabled(false);
							jStep3Label7.setVisible(true);
							jButton1.setEnabled(true);
							
						}
						else{
							if((!jLabel1.isVisible())&&(!jStep2Label11.isVisible())&&(jStep3Label7.isVisible())){
								
								if(isDigit(jTextField3.getText().trim())&& isDigit(jTextField2.getText().trim()) && !jTextField3.getText().trim().equals("") && !jTextField2.getText().trim().equals("")){
									double num1= Double.valueOf(jTextField3.getText().trim());
									double num2= Double.valueOf(jTextField2.getText().trim());   
																		
									if((num1>100 && num2>100) || (num1<0 && num2<0)){
										
										jLabel8.setForeground(java.awt.Color.red);
										jLabel8.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.BOLD, 11));
										jLabel9.setForeground(java.awt.Color.red);
										jLabel9.setFont(new java.awt.Font("Microsoft Sans Serif",java.awt.Font.BOLD, 11));
										jButton1.setEnabled(true);
									}else {
										if(num1>100 || num2>100 || num1<0 || num2<0){ 
											
											if((num2>100 || num2<0)&&(num1>100 || num1<0)){
												jLabel8.setForeground(java.awt.Color.red);
												jLabel8.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.BOLD, 11));
												jLabel9.setForeground(java.awt.Color.red);
												jLabel9.setFont(new java.awt.Font("Microsoft Sans Serif",java.awt.Font.BOLD, 11));
												jButton1.setEnabled(true);
											}
											else{
												if(num1>100 || num1<0){
													jLabel9.setForeground(java.awt.Color.red);
													jLabel9.setFont(new java.awt.Font("Microsoft Sans Serif",java.awt.Font.BOLD, 11));
													jButton1.setEnabled(true);
												}else{
													jLabel8.setForeground(java.awt.Color.red);
													jLabel8.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.BOLD, 11));
													jButton1.setEnabled(true);
													
												}
											}
										} 
										
										
										else{  
											
											relationCopy.removeAllElements();
											relationCopy.addAll(relation.getAtributes());
											jComboBox.removeAllItems();
											for (int i = 0; i < relationCopy.size(); i++) {
												jComboBox.addItem(relationCopy.elementAt(i).getName());
											}
											jButton1.setEnabled(false);
											jerrorLabel7.setVisible(false);
											AssociationRule assoc1= assocManager.getAssociations().lastElement();
											
											System.out.println("total asoc antes del borrado: "+assocManager.getAssociations().size());
											assocManager.getAssociations().removeElementAt(assocManager.getAssociations().size()-1);
											
											//System.out.println("total asoc DESPUES del borrado: "+assocManager.getAssociations().size());
											
											int conf = Integer.parseInt(jTextField3.getText());
											assoc1.setConfidence(conf);
											int supp = Integer.parseInt(jTextField2.getText());
											assoc1.setSupport(supp);
											assocManager.setAssociation(assoc1);
											
											System.out.println("total asoc DESPUES del borrado: "+assocManager.getAssociations().size());
											
											Vector ant = assoc1.getAntecedents();
											Vector cons = assoc1.getConsecuents();
											String antecedent= "";
											
											for (int i = 0; i < ant.size(); i+=2) {
												if(i == 0){
													//antecedent+="  "; 
													antecedent+=ant.elementAt(i).toString()+" = ";
													antecedent+=ant.elementAt(i+1).toString()+" ";
													
												}else{
													antecedent+=","+ant.elementAt(i).toString()+" = ";
													antecedent+=ant.elementAt(i+1).toString()+" ";
												}
											}
											antecedent+= "   ===>>>   ";
											
											for (int i = 0; i < cons.size(); i+=2) {
												if(i == 0){
													antecedent+=cons.elementAt(i).toString()+" = ";
													antecedent+=cons.elementAt(i+1).toString()+" ";
												}
												else{
													antecedent+=","+cons.elementAt(i).toString()+" = ";
													antecedent+=cons.elementAt(i+1).toString()+" ";
												}
											}
											if((assoc1.getSupport()>=0)&&(assoc1.getSupport()<10)&&(assoc1.getConfidence()>=0)&&(assoc1.getConfidence()<10)){
												antecedent+="    supp:(0.0"+assoc1.getSupport()+") conf:(0.0"+assoc1.getConfidence()+")";
											}else{
												if((assoc1.getSupport()>9)&&(assoc1.getSupport()<100)&&(assoc1.getConfidence()>9)&&(assoc1.getConfidence()<100)){
													antecedent+="    supp:(0."+assoc1.getSupport()+") conf:(0."+assoc1.getConfidence()+")";
												}else
													if((assoc1.getSupport()==100)&&(assoc1.getConfidence()<100)&&(assoc1.getConfidence()>9)){
														antecedent+="    supp:(1) conf:(0."+assoc1.getConfidence()+")";
													}else{
														if((assoc1.getSupport()>9)&&(assoc1.getSupport()<100)&&(assoc1.getConfidence()==100)){
															antecedent+="    supp:(0."+assoc1.getSupport()+") conf:(1)";
														}else{
															if((assoc1.getSupport()==100)&&(assoc1.getConfidence()==100))
																antecedent+="    supp:(1) conf:(1)";
															else{
																if((assoc1.getSupport()==100)&&(assoc1.getConfidence()<10)&&(assoc1.getConfidence()>=0)){
																	antecedent+="    supp:(1) conf:(0.0"+assoc1.getConfidence()+")";
																}
																else{
																	if((assoc1.getSupport()>=0)&&(assoc1.getSupport()<10)&&(assoc1.getConfidence()==100)){
																		antecedent+="    supp:(0.0"+assoc1.getSupport()+") conf:(1)";
																	}
																}
															}
														}
														
													}
												
											}
											String anterior="";
											if(jTextArea != null){	
												anterior = jTextArea.getText();
												anterior+=antecedent;
											}else{
												anterior=antecedent;
											}
											
											jTextArea.setText(anterior+'\n');
											jLabel1.setVisible(true);
											jStep2Label11.setVisible(false);
											jLabel2.setVisible(true);
											jLabel3.setVisible(true);
											jLabel4.setVisible(true);					
											jComboBox.setVisible(true);
											jComboBox1.setVisible(true);
											jTextField.setText("");
											jTextField.setVisible(true);
											jTextField.setEditable(false);
											jLabel5.setVisible(false);
											jLabel6.setVisible(false);
											jTextField2.setText("");
											jTextField3.setText("");
											jTextField2.setVisible(false);
											jTextField3.setVisible(false);
											jLabel8.setVisible(false);
											jLabel9.setVisible(false);
											jButton.setEnabled(true);
											jStep3Label7.setVisible(false);
											jComboBox.setSelectedIndex(-1);
											jComboBox1.setSelectedIndex(-1);
											
										}
									}
								}else{ 
									jerrorLabel7.setText("Please, put integer value");
									jerrorLabel7.setVisible(true);
									jButton1.setEnabled(true);
								}
								
								
								
								
								
							}
							
						}
						
					}
					
					
				}
				
			});
		}
		return jButton1;
	}
	
	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox() {
		
		if (jComboBox == null) {
			jComboBox = new JComboBox();
			jComboBox.removeAllItems();
			
			
			//agregar todos los elementos de attribute
			//relation = RelationManager.instanceRelationManager.getRelation();
			relationCopy.addAll(relation.getAtributes());
			
			for (int i = 0; i < relation.getAtributes().size(); i++) {
				jComboBox.addItem(relationCopy.elementAt(i).getName());
			}
			
			jComboBox.setLocation(new java.awt.Point(106,36));
			jComboBox.setSize(new java.awt.Dimension(85,21));
			jComboBox.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			
			jComboBox.addItemListener(new java.awt.event.ItemListener() {
				@SuppressWarnings("unchecked")
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					
					
					
					if(jComboBox.getSelectedIndex() != -1){
						//Attribute attribute = relation.getAtributes().elementAt(pos);
						int pos =  jComboBox.getSelectedIndex();
						jTextField.setText(relationCopy.elementAt(pos).getType());
						jTextField.setEditable(false);
						if(jComboBox1 != null)
							jComboBox1.removeAllItems();  
						Vector values = new Vector();
						values.addAll(relationCopy.elementAt(pos).getValues());
						
						
						for (int i = 0; i < values.size(); i++) {
							
							jComboBox1.addItem(values.elementAt(i).toString());
						} 
					} 
					
				}
			});
		}
		
		jComboBox.setSelectedIndex(-1);
		return jComboBox;
	}
	
	/**
	 * This method initializes jButton2	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new JButton();
			jButton2.setLocation(new java.awt.Point(298,505));
			jButton2.setText("Cancel");
			jButton2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jButton2.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jButton2.setBackground(java.awt.SystemColor.control);
			jButton2.setSize(new java.awt.Dimension(75,23));
			jButton2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dispose();
				}
			});
		}
		return jButton2;
	}
	
	/**
	 * This method initializes jButton3	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton3() {
		if (jButton3 == null) {
			jButton3 = new JButton();
			jButton3.setLocation(new java.awt.Point(195,505));
			jButton3.setText("Generate");
			jButton3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jButton3.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jButton3.setBackground(java.awt.SystemColor.control);
			jButton3.setSize(new java.awt.Dimension(75,23));
			jButton3.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					//aca va lo de generar data con las reglas de asociacion
					
					assocManager.createFormat();
					assocManager.deleteRecurrentData();
					assocManager.deleteDataIncluded();
					assocManager.dataGeneratorWithRules();			
					String data="";
					for (int i = 0; i < assocManager.getDataGenerated().size(); i++) {
						data=assocManager.getDataGenerated().elementAt(i);
						System.out.println("DataGenerated pos: "+i+"  tiene---> "+data);
					}
					
					assocManager.printRules(jTextArea.getText());
										
					dispose();
				}
			});
		}
		return jButton3;
	}
	
	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setText("");
			jTextField.setEditable(false);
			jTextField.setBounds(new java.awt.Rectangle(106,61,85,21));
		}
		return jTextField;
	}
	
	/**
	 * This method initializes jTextField2	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField2() {
		if (jTextField2 == null) {
			jTextField2 = new JTextField();
			jTextField2.setSize(new java.awt.Dimension(35,22));
			jTextField2.setLocation(new java.awt.Point(106,36));
			jTextField2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
			jTextField2.setVisible(false);
		}
		return jTextField2;
	}
	
	/**
	 * This method initializes jTextField3	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField3() {
		if (jTextField3 == null) {
			jTextField3 = new JTextField();
			jTextField3.setLocation(new java.awt.Point(106,61));
			jTextField3.setSize(new java.awt.Dimension(35,22));
			jTextField3.setHorizontalAlignment(javax.swing.JTextField.CENTER);
			jTextField3.setVisible(false);
		}
		return jTextField3;
	}
	
	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new java.awt.Rectangle(15,145,496,291));
			jScrollPane.setViewportBorder(javax.swing.BorderFactory.createCompoundBorder(null, null));
			jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
			jScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
			jScrollPane.setViewportView(getJTextArea());
			jScrollPane.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.blue,1));
		}
		return jScrollPane;
	}
	
	/**
	 * This method initializes jRulesPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJRulesPanel1() {
		if (jRulesPanel1 == null) {
			jRulesLabel7 = new JLabel();
			jRulesLabel7.setText("R U L E S");
			jRulesLabel7.setLocation(new java.awt.Point(1,0));
			jRulesLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			jRulesLabel7.setForeground(java.awt.Color.blue);
			jRulesLabel7.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.BOLD, 11));
			jRulesLabel7.setBackground(java.awt.SystemColor.activeCaptionBorder);
			jRulesLabel7.setSize(new java.awt.Dimension(94,30));
			jRulesPanel1 = new JPanel();
			jRulesPanel1.setLayout(null);
			jRulesPanel1.setBackground(java.awt.SystemColor.activeCaptionBorder);
			jRulesPanel1.setSize(new java.awt.Dimension(95,30));
			jRulesPanel1.setLocation(new java.awt.Point(15,116));
			jRulesPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.blue,1));
			jRulesPanel1.add(jRulesLabel7, null);
		}
		return jRulesPanel1;
	}
	
	/**
	 * This method initializes jComboBox1	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox1() {
		if (jComboBox1 == null) {
			jComboBox1 = new JComboBox();
			//jComboBox1.removeAllItems();
			jComboBox1.setLocation(new java.awt.Point(106,86));
			jComboBox1.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.PLAIN, 11));
			jComboBox1.setSize(new java.awt.Dimension(85,21));
		}
		return jComboBox1;
	}
	
	/**
	 * This method initializes jTextArea	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getJTextArea() {
		if (jTextArea == null) {
			jTextArea = new JTextArea();
			jTextArea.setEditable(false);
			jTextArea.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD, 11));
		}
		return jTextArea;
	}
	
	public boolean isDigit(String value){
		boolean flag=true;
		
		for (int i = 0; i < value.length(); i++) {
			if(!Character.isDigit(value.charAt(i))&&(!value.startsWith("-"))){
				flag=false;
			}
			
		}
		
		return flag;
	}
	
	
	
	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED));
			jPanel1.setLayout(null);
			jPanel1.setBounds(new java.awt.Rectangle(303,32,207,85));
			jPanel1.setBackground(java.awt.SystemColor.activeCaptionBorder);
			jPanel1.add(getJButton(), null);
			jPanel1.add(getJButton1(), null);
		}
		return jPanel1;
	}

	/**
	 * This method initializes jHelpButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJHelpButton() {
		if (jHelpButton == null) {
			jHelpButton = new JButton();
			jHelpButton.setText("Help");
			jHelpButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jHelpButton.setSize(new java.awt.Dimension(55,35));
			jHelpButton.setLocation(new java.awt.Point(484,503));
			jHelpButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					new HelpFrame(Message.TITLE_RANDOM_ASSOCIATION,Message.BODY_RANDOM_ASSOCIATION).show();
				}
			});
		}
		return jHelpButton;
	}
	
//	@SuppressWarnings("deprecation")
//	public static void main(String[] args) {
//		
//		RelationManager.createInstance();
//		Attribute att = new NominalAttribute(false,"deporte","nominal","futbol,tenis,voley,paddle");
//		Attribute att1 = new NominalAttribute(false,"marcas_autos","nominal","ford,peugeot,renault,ferrari");
//		Vector<Attribute> atributex = new Vector<Attribute>();
//		atributex.addElement(att);
//		atributex.addElement(att1);
//		Relation relation= new Relation(atributex,"el_pepe",20);
//		
//		RelationManager.instance.setRelations(relation);
//		new Association().show();
//		
//	}
	
	
}  //  @jve:decl-index=0:visual-constraint="10,10"

